package cn.edu.swu.cly.auth;

import cn.edu.swu.cly.repo.ResultSetVisitor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UserResultSetVisitor implements ResultSetVisitor<User> {   //范形集合，返回的是User

    public List<User> visit(ResultSet rs) throws SQLException{
        List<User> users = new ArrayList<>();
        while (rs.next()) {
            User user = new User();
            user.setId(rs.getInt("id"));
            user.setName(rs.getString("name"));
            user.setPasswd(rs.getString("passwd"));
            user.setRole(rs.getString("role"));

            users.add(user);
        }
        return  users;
    }
}
